#include "pack.h"

#include <arm_sve.h>

#include <cstdio>
#include <stdexcept>
// Pack 2 INT4 value into 1 INT8
void pack(uint8_t* dst, const uint8_t* src, const size_t n) {
  for (size_t i = 0; i < n; i += 2) {
    uint8_t hi = src[i] & 0xF;
    uint8_t lo = src[i + 1] & 0xF;
    dst[i / 2] = (hi << 4) | lo;
  }
}

// Unpack 1 INT8 value into 2 INT4
void unpack(uint8_t* dst, const uint8_t* src, const size_t n) {
  for (size_t i = 0; i < n; i += 2) {
    uint8_t hi = src[i / 2] >> 4;
    uint8_t lo = src[i / 2] & 0xF;
    dst[i] = hi;
    dst[i + 1] = lo;
  }
}

void unpack_sve(uint8_t* dst, const uint8_t* src, const size_t n) {
  // SVE implementation is not yet complete.
  throw std::runtime_error("SVE unpack implementation is not yet complete.");
}